<%@ page pageEncoding="UTF-8"%>
<%@ include file="../common/head.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>${appTitle }</title>
<link href="${ctx}/qiantai/assets/layui-v2.5.6/layui/css/layui.css" rel="stylesheet">
<link href="${ctx}/qiantai/assets/css/plugins.css" rel="stylesheet">
<link href="${ctx}/qiantai/assets/css/styles.css" rel="stylesheet">
<link href="${ctx}/qiantai/assets/css/skin/default.css" rel="stylesheet">
<meta name="referrer" content="no-referrer">
<style type="text/css">
input[type="text"] {
	border-left-width: 0px;
	border-top-width: 0px;
	border-right-width: 0px;
	border-bottom-color:
	height: 30px;
	margin-bottom: 20px;
	color: gray;
}

textarea {
	margin-bottom: 20px;
	color: gray;
}
</style>
</head>

<body class="green-skin bg-light">
	
	<div id="main-wrapper">
		<!-- Start Navigation -->
		<%@ include file="./header.jsp"%>
		<!-- End Navigation -->
		<div class="clearfix"></div>

		<div class="container-fluid breadcrumbs breadcrumbs-light">
			<div class="container">
				<div class="row">
					<div class="col-xs-12">
						<a href="${ctx }/"> 首页 </a>
						<a href="${ctx }/com/index.do">
							<span>
								<i class="ti-arrow-right"></i>
							</span>
							${modifybean.name }
						</a>
					</div>
				</div>
			</div>
		</div>
		<section class="tr-single-detail gray-bg">
			<div class="container">
				<div class="row">
					<div class="col-md-12 col-sm-12">
						<article class="blog-news big-detail-wrap">
							<h3>${modifybean.name }</h3>
							<hr />
							<form action="${ctx}/com/addQuesUser.do" id="j_custom_form" data-toggle="ajaxform">
								<input type="hidden" value="${modifybean.id}" name="quesId" />
								<div>
									<c:forEach items="${list }" var="item">
										<fieldset>
											<legend style="font-weight: normal;">${item.name }：</legend>
											<c:forEach items="${item.list }" var="itemlist" varStatus="itemliststa">
												<div class="bs-callout bs-callout-warning">
													<h4>${itemliststa.count}.${itemlist.question }</h4>
													<c:if test="${itemlist.typesel=='单选' }">
														<p>
															<c:forEach items="${itemlist.list}" var="ansitem">
																<input  style="position: relative; left: 0px" type="radio" name="score_${itemlist.id}"
																	id="score_${itemlist.id}" value="${ansitem.id }"> ${ansitem.options }<br />
															</c:forEach>
														</p>
													</c:if>
													<c:if test="${itemlist.typesel=='多选' }">
														<p>
															<c:forEach items="${itemlist.list}" var="ansitem">
																<input  type="checkbox" name="score_${itemlist.id}" value="${ansitem.id }" id="score_${itemlist.id}"> ${ansitem.options }<br />
															</c:forEach>
														</p>
													</c:if>
													<c:if test="${itemlist.typesel=='填空' }">
														<p>
															<input type="text" name="score_${itemlist.id}" id="score_${itemlist.id}" data-rule="${itemlist.check}"
																maxlength="${itemlist.maxlength}" size="100" data-tit="${itemlist.question }">
														</p>
													</c:if>
													<c:if test="${itemlist.typesel=='文本' }">
														<p>
															<textarea rows="5" cols="100" name="score_${itemlist.id}" id="score_${itemlist.id}" data-tit="${itemlist.question }"
																class="layui-textarea" maxlength="${itemlist.maxlength}"></textarea>
														</p>
													</c:if>
												</div>
											</c:forEach>
										</fieldset>
										<hr />
									</c:forEach>
								</div>
							</form>
							<input type="button" value="提交" class="layui-btn" onclick="tijiao()">
						</article>
					</div>
				</div>
			</div>
		</section>
		<%@ include file="./footer.jsp"%>
	</div>
	<script src="${ctx}/qiantai/assets/js/jquery.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/popper.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/bootstrap.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/select2.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/aos.js"></script>
	<script src="${ctx}/qiantai/assets/js/perfect-scrollbar.jquery.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/owl.carousel.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/jquery.counterup.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/slick.js"></script>
	<script src="${ctx}/qiantai/assets/js/bootstrap-datepicker.js"></script>
	<script src="${ctx}/qiantai/assets/js/isotope.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/summernote.js"></script>
	<script src="${ctx}/qiantai/assets/js/jQuery.style.switcher.js"></script>

	<script src="${ctx}/qiantai/assets/js/counterup.min.js"></script>
	<script src="${ctx}/qiantai/assets/js/custom.js"></script>
	<script src="${ctx}/qiantai/assets/layui-v2.5.6/layui/layui.js"></script>
	<script type="text/javascript">
		function tijiao() {
			var count = 0;
			var radios = $("input[type='radio']");
			for (var i = 0; i < radios.length; i++) {
				var rid = radios[i].id;
				var list = $('input:radio[id="' + rid + '"]:checked').val();
				if (list == null) {
					zzz("请回答所有问题");return false;
				}
			}
			var checkboxs = $("input[type='checkbox']");
			for (var i = 0; i < checkboxs.length; i++) {
				var rid = checkboxs[i].id;
				var list = $('input:checkbox[id="' + rid + '"]:checked').val();
				if (list == null) {
					zzz("请回答所有问题");return false;
				}
			}
			var texts = $("input[type='text']");
			//根据 name集合长度 遍历name集合  
			for (var i = 0; i < texts.length; i++) {
				var rid = texts[i].id;
				var list = $('input:text[id="' + rid + '"]').val();
				var title = $(texts[i]).attr("data-tit");
				var rule = $(texts[i]).attr("data-rule");
				console.log(title);
				if (list == null || list == "") {
					zzz("请回答所有问题: "+title);return false;
				}else{
					if(!checkone(rule,list)){
						zzz("输入错误: "+title);return false;
					}
				}
	
			}
			var textareas = $("textarea[name^='score_']");
			//根据 name集合长度 遍历name集合  
			for (var i = 0; i < textareas.length; i++) {
				var rid = textareas[i].id;
				var list = $('textarea[id="' + rid + '"]').val();
				var title = $(textareas[i]).attr("data-tit");
				if (list == null || list == "") {
					zzz("请回答所有问题: "+title);return false;
				}
			}
			$("#j_custom_form").submit();
		}
		function checkone(rule,val){
			if("number"==rule){
				return checknumber(val);
			}
			if("email"==rule){
				return checkemail(val);
			}
			if("cn"==rule){
				return checkcn(val);
			}
			if("en"==rule){
				return checken(val);
			}
			if("url"==rule){
				return checkurl(val);
			}
			if("idcard"==rule){
				return checkidcard(val);
			}
			if("phone"==rule){
				return checkphone(val);
			}
			return true;
		}
		function checkphone(val){
			var reg = /^1[2-9]\d{9}$/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		function checkidcard(val){
			var reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		function checkurl(val){
			var reg = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		function checknumber(val){
			return val%1 === 0;
		}
		function checkemail(val){
			var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		function checkcn(val){
			var reg = /^[\u4E00-\u9FA5]{2,4}$/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		function checken(val){
			var reg = /^[A-Za-z]+$/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		layui.use([ 'laydate'], function() {
			var laydate = layui.laydate;
			var form = layui.form;
			lay('input[data-rule="date"]').each(function() {
				$(this).attr("readonly","readonly");
				laydate.render({
					elem : this,
					type : "date", //year,month,date,time,datetime
					range : false, //范围
					format : "yyyy-MM-dd",
					trigger: 'click',
				//value : "",//默认值
				//min/max - 最小/大范围内的日期时间值,正负值
				});
			});
		});
	</script>
	<%@ include file="./msg.jsp"%>
</body>
</html>